package com.viphuli.app.tool.handler;


import com.offroader.utils.ViewUtils;
import com.viphuli.app.tool.R;
import com.viphuli.app.tool.bean.page.CommonPage;
import com.viphuli.app.tool.bean.part.AccountUser;
import com.viphuli.app.tool.common.AccessTokenKeeper;
import com.viphuli.app.tool.fragment.AccountFragment;
import com.viphuli.app.tool.fragment.AccountTypeDialogFragment;

public class AccountUserTypeResponseHandler extends MyBaseHttpResponseHandler<AccountTypeDialogFragment, CommonPage> {

	@Override
	public void deal() {

		if (!caller.isAdded())
			return;

		String name = caller.getSelectUserType().getName();

		//获得页面fragment
		AccountFragment frag = (AccountFragment) caller.getActivity().getSupportFragmentManager().findFragmentById(R.id.container);
		frag.getUserType().setText(name);

		AccessTokenKeeper tokenKeeper = AccessTokenKeeper.readAccessToken(caller.getActivity());
		AccountUser user = tokenKeeper.getUser();
		user.setUserType(caller.getSelectUserType().getValue());
		AccessTokenKeeper.keepAccessToken(caller.getActivity(), tokenKeeper);

		ViewUtils.toast(page.getResultMsg());

		//关闭当前dialog
		caller.dismiss();

	}

}
